package com.kancy.jemeter.functions;

import com.kancy.jemeter.util.IDCardUtil;
import com.kancy.jemeter.util.MessageUtil;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;

import java.util.LinkedList;
import java.util.List;

/**
 * @author kancy
 * @date 2019/6/29 17:17
 */
public class AreaCodeFunction extends JemeterAbstractFunction {

	public AreaCodeFunction() {
		super(0,2);
	}

	@Override
	public String execute(SampleResult sampleResult, Sampler sampler) throws InvalidVariableException {
		String districtcode = IDCardUtil.getdistrictcode();
		setJMeterVariable(0, districtcode);
		if (hasParameter(1)){
			setJMeterVariable(1, IDCardUtil.parseAddress(districtcode));
		}
		return districtcode;
	}


	private static final List<String> argumentDesclist = new LinkedList();

	static {
		argumentDesclist.add(MessageUtil.getResString("varname.message"));
		argumentDesclist.add(MessageUtil.getResString("__areacode.address.varname.message"));
	}
	@Override
	public List<String> getArgumentDesc() {
		return argumentDesclist;
	}

}
